package com.itheima.service.Impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import com.itheima.util.MD5Utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;
    @Override
    public Member findByThlephone(String telephone) {
        Member member = memberDao.findByTelephone(telephone);
        return member;
    }

    @Override
    public void add(Member member) {
        String password = member.getPassword();
        if (password!=null){
            String s = MD5Utils.md5(password);
            member.setPassword(s);
        }
        memberDao.add(member);
    }
//查询会员年龄分布
    @Override
    public Map<String, Object> getMemberAge() {
        List<Map<String,Object>> list=memberDao.getMemberAge();
        //分组名称list集合
        List list1=new ArrayList();
        List list2=new ArrayList();
        for (Map<String, Object> map : list) {
           list1.add(map.get("nld"));
           list2.add(map.get("number"));
        }
        Map<String,Object> map=new HashMap<>();
        map.put("nameMap",list1);
        map.put("countMap",list2);
        return map;
    }
}
